package ink.metoo.auto.fishpi.chatroom.command

import ink.metoo.auto.fishpi.Log
import ink.metoo.auto.fishpi.call.ChatRoomCall
import ink.metoo.auto.fishpi.chatroom.ChatRooms
import ink.metoo.auto.fishpi.chatroom.Message

class TopicCommand : Command {

    override val commandText: String
        get() = "/话题"

    override fun isMatch(message: Message): Boolean {
        return super.isMatch(message) && message.isMe
    }

    override fun execute(message: Message) {
        val params = message.commandParams
        val topic = params.getOrNull(1)
        if (topic.isNullOrBlank()) {
            ChatRooms.systemConsole(content = "当前话题为: ${ChatRooms.discussing}")
            return
        }
        val result = ChatRoomCall.modifyTopic(topic)
        Log.debug("话题变更结果: {}", result.code == 0)
    }
}